package com.xingchi.tornado.security.model;

import lombok.Getter;
import lombok.Setter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 手机号认证token
 *
 * @author xiaoya
 * @date 2024/9/27 14:35
 */
@Getter
@Setter
public class MobileAuthenticationToken extends AbstractAuthenticationToken {

    /**
     * 手机号
     */
    private String mobile;

    /**
     * 手机号验证码
     */
    private String code;

    public MobileAuthenticationToken() {
        super(new ArrayList<>());
    }

    public MobileAuthenticationToken(String mobile, String code, boolean isAuthenticated, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.mobile = mobile;
        this.code = code;
        this.setAuthenticated(isAuthenticated);
    }

    @Override
    public Object getCredentials() {
        return code;
    }

    @Override
    public Object getPrincipal() {
        return mobile;
    }
}
